<?php
/**
 * Created by 王跃达.
 * User: 小马出行
 * Date: 2017/8/24
 * Time: 16:17
 */

namespace app\api\logic;


use app\api\model\OrderModel;
use think\Model;

class OrderLogic extends Model
{


    public function __construct()
    {
        parent::__construct();

    }
    /**
     * 客户端下单前的城市搜索按大写字母排序
     * @param string 
     * @param int 
     * @return mixed//成功时返回
     */
    public function citySearch(){
        $orderModel = new OrderModel();
        return $orderModel->citySearch();
    }
    /**
     * 生成订单
     * @param $data
     * @return string 自增ID
     */
    public function createOrder($data)
    {
        $orderModel = new OrderModel();
        return $orderModel->createOrder($data);
    }
    /**
     * 订单日志
     * @param string 
     * @param int 
     * @return mixed//成功时返回
     */
    public function createOrderLog($data){
        $orderModel = new OrderModel();
        return $orderModel->createOrderLog($data);
    }
    /**
     * 用户充值订单
     * @param string 
     * @param int 
     * @return mixed
     */
    public function createRecharge($uid, $money,$return_money,$type,$recharge_id){
        $orderModel = new OrderModel();
        return $orderModel->createRecharge($uid, $money,$return_money,$$type,$recharge_id);
    }
    /**
     * 未完成订单
     * @param $uid
     * @return array 未完成的订单的单号 状态
     */
    public function findUnfinishedOrder($uid)
    {
        $orderModel = new OrderModel();
        return $orderModel->findUnfinishedOrder($uid);
    }

    /**
     * 根据订单号获取订单信息
     * @param $uid
     * @param $common_id
     * @param $field
     * @return array|false|\PDOStatement|string|Model
     */
    public function getOrderByOrderSn($uid, $common_id,$field="*")
    {
        $orderModel = new OrderModel();
        return $orderModel->getOrderByOrderSn($uid, $common_id,$field);
    }

    /**
     * 根据UID获取所有订单
     * @param $uid
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function getOrderListByUid($uid,$field="*")
    {
        $orderModel = new OrderModel();
        return $orderModel->getOrderListByUid($uid,$field);
    }
    /**
     * 乘客付款时处理的数据
     *
     **/
     public function setOrderData($common_id,$data){
        $orderModel = new OrderModel();
        return $orderModel->setOrderData($common_id,$data);
        
     }
    /**
     * 乘客付款时处理的数据
     *
     **/
    public function setOrderSnData($order_sn,$data){
        $orderModel = new OrderModel();
        return $orderModel->setOrderSnData($order_sn,$data);

    }

    /**
     * 根据用户id获取本月用户强制取消的订单数
     * @param $uid
     * @return mixed
     **/
    public function getForceCancelCountMonthByUid($uid)
    {
        $model = new OrderModel();
        $map['uid'] = $uid;
        $start = strtotime(date('Y-m-01'));$end = strtotime(date('Y-m-t 23:59:59'));
        $map['cancel_time'] = array('between',array($start,$end));
        return $model->getForceCancelCount($map);
    }

    public function getOrderById($id,$field)
    {
        $model = new OrderModel();
        return $model->getOrderById($id,$field);
    }
}